package com.company.Stack;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}20:40
 */
public class ArrayStack {
    private int MaxTop;//栈的大小；
    private int[] stack;
    private int top = -1;

    //确定栈的上限
    public ArrayStack(int maxTop) {
        MaxTop = maxTop;
        stack = new int[maxTop];
    }

    //判断是否为空
    public void isEmpty(){
        if (top==-1){
            throw new RuntimeException("栈为空");
        }
    }

    //判断是否满栈
    public void isFull(){
        if (top==MaxTop){
            throw new RuntimeException("栈已满");
        }
    }

    //压栈
    public void pushStack(int value){
//            isEmpty();
        isFull();
        top++;
        stack[top] = value;
    }

    //出栈
    public void popStack(){
        isEmpty();
        while (top!=-1) {
            int value = stack[top];
            System.out.println("出栈的为" +top+"节点："+ value);
            top--;
        }
    }
}
